package tests;

import java.sql.ResultSet;
import java.util.ArrayList;

import org.junit.Assert;
import org.junit.Test;

import com.davinci.freemarket.dataAccessLayer.accessdata.comment.CommentDAO;
import com.davinci.freemarket.dataAccessLayer.accessdata.user.UserDAO;
import com.davinci.freemarket.dataModelLayer.model.DBAttibuteModel;
import com.microsoft.sqlserver.jdbc.SQLServerException;

/**
 * 
 * @author Lucas Buyo
 *
 */
public class CommentsUnitTesting 
{
	
	@Test
	public void selectComments(){
		CommentDAO commentdao = new CommentDAO();
		
		ArrayList<DBAttibuteModel> conditions = new ArrayList<DBAttibuteModel>();
//		conditions.add(new DBAttibuteModel("ID_PUBLI", "2"));
//		conditions.add(new DBAttibuteModel("ID_USER", "11"));
		conditions.add(new DBAttibuteModel("PREGUNTA", "%Esta es una %"));
		
		ResultSet rs = commentdao.selectComments(conditions, "LIKE");
		Assert.assertTrue(rs != null);
		String result = "";
		try {
			while (rs.next()) {
				result += rs.getString(1) + ", " + rs.getString(2) + ", " +rs.getString(3) + ", " +rs.getString(4) + ", " +rs.getString(5)+ ", " +rs.getString(6) + "\n";
			}
			System.out.println(result);
		}
		catch (SQLServerException e) {
			System.out.println(e);
		}
		catch (Exception e) {
			System.out.println(e);
		}
		
		commentdao.closeConnection();
	}
	
	@Test
	public void addComment(){
		CommentDAO commentdao = new CommentDAO();
		int rs = commentdao.addComment(11, "Esta es una test pregunta", 2, false);
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	public void addAnswer(){
		CommentDAO commentdao = new CommentDAO();
		int rs = commentdao.addAnswer(3, "Esta es una test respuesta al comentario");
		Assert.assertTrue(rs != 0);
	}
	
	@Test
	public void deleteComment(){
		CommentDAO commentdao = new CommentDAO();
		int rs = commentdao.deleteComment(4);
		Assert.assertTrue(rs != 0);
	}

}
